package com.zx.crowdfunding.mvc.handler;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;
import com.zx.crowdfunding.service.api.SessionService;
import com.zx.crowdfunding.util.ResultEntity;

/**
 * 会话 - Handler
 * @author 郑雪
 * @date 2021-12-18
 */
@Controller
public class SessionHandler {

	/**
	 * 会话Service接口
	 */
	@Autowired
	private SessionService sessionService;
	
	/**
	 * 会话获取分页数据
	 * @param keyword 查询的关键字，默认为""
	 * @param pageNum 分页的页码，默认为1
	 * @param pageSize 分页的大小，默认为5
	 * @return JSON数据
	 */
	@RequestMapping("/session/get/page.json")
	@ResponseBody
	public ResultEntity<PageInfo<Map<String, Object>>> getPageInfo(
				@RequestParam(value="keyword", defaultValue="") String keyword, 
				@RequestParam(value="pageNum", defaultValue="1") Integer pageNum, 
				@RequestParam(value="pageSize", defaultValue="5") Integer pageSize
			){
		
		// 调用Service方法获取PageInfo对象
		PageInfo<Map<String, Object>> pageInfo = sessionService.getPageInfo(keyword, pageNum, pageSize);
		
		// 返回JSON数据
		return ResultEntity.successWithData(pageInfo);
	}
	
}
